﻿package mortal.game.view.mail.view
{
    import Message.Game.*;
    import com.gengine.utils.*;
    import com.mui.controls.*;
    import com.mui.display.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.global.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.manager.msgTip.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.common.*;
    import mortal.mvc.core.*;

    public class MailListItem extends GCellRenderer
    {
        private var _bg:ScaleBitmap;
        private var _txtType:GTextFiled;
        private var _txtStaticTitle:GTextFiled;
        private var _txtDate:GTextFiled;
        private var _txtStatus:GTextFiled;
        private var _txtTitle:GTextFiled;
        private var _bmpStatus:GBitmap;
        private var _bmpAttachment:GBitmap;
        private var _btnGetAttachment:GButton;
        private var _checkBox:GCheckBox;

        public function MailListItem()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this._bg = UIFactory.bg(0, 0, 287, 50, this, "InputDisablBg");
            this._checkBox = UIFactory.checkBox("", 8, 11, 28, 28, this);
            var _loc_1:* = new TextFormat();
            _loc_1.color = GlobalStyle.colorHuangUint;
            var _loc_2:* = new TextFormat();
            _loc_1.color = GlobalStyle.colorHongUint;
            this._txtType = UIFactory.textField("", 30, 2, 65, 30, this, null, false, false);
            this._txtType.textColor = 16777215;
            this._txtDate = UIFactory.textField("", 85, 2, 75, 30, this, null, false, false);
            this._txtStatus = UIFactory.textField("", 160, 2, 65, 30, this, _loc_1, false, false);
            this._txtStaticTitle = UIFactory.textField("标     题", 30, 25, 65, 30, this, null, false, false);
            this._txtStaticTitle.textColor = 16777215;
            this._txtTitle = UIFactory.textField("", 85, 25, 160, 30, this, null, false, false);
            this._btnGetAttachment = UIFactory.gButton("提取", 235, 24, 50, 22, this);
            this._btnGetAttachment.configEventListener(MouseEvent.CLICK, this.btnGetAttachmentHandler);
            this.configEventListener(MouseEvent.CLICK, this.clickHandler, false, 9999999);
            return;
        }// end function

        private function clickHandler(event:MouseEvent) : void
        {
            if (event.target == this._btnGetAttachment)
            {
                event.stopImmediatePropagation();
                event.stopPropagation();
                Dispatcher.dispatchEvent(new DataEvent(EventName.MailGetAttachment));
            }
            else if (event.target == this._checkBox)
            {
                event.stopImmediatePropagation();
                event.stopPropagation();
                this.mailSelected = this._checkBox.selected;
            }
            return;
        }// end function

        private function btnGetAttachmentHandler(event:MouseEvent) : void
        {
            if (Cache.instance.pack.backPackCache.isPackFull())
            {
                return MsgManager.showRollTipsMsg("背包已满", MsgRollTipsType.msgRollTips3);
            }
            if (Cache.instance.pack.backPackCache.leftCapacity < Cache.instance.mail.getMailAttachItemCount(this._data as SMail))
            {
                MsgManager.showRollTipsMsg("背包空位不足");
                return;
            }
            var _loc_2:Object = {};
            _loc_2.mailId = _data.mailId;
            _loc_2.attachementIndex = 0;
            _loc_2.isDelete = Cache.instance.mail.mailGetAfterDelete;
            Dispatcher.dispatchEvent(new DataEvent(EventName.MailGetAttachment, _loc_2));
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._bg.dispose(param1);
            this._checkBox.dispose(param1);
            this._txtType.dispose(param1);
            this._txtDate.dispose(param1);
            this._txtStatus.dispose(param1);
            this._txtStaticTitle.dispose(param1);
            this._txtTitle.dispose(param1);
            this._btnGetAttachment.dispose(param1);
            if (this._bmpStatus)
            {
                this._bmpStatus.dispose(param1);
            }
            if (this._bmpAttachment)
            {
                this._bmpAttachment.dispose(param1);
            }
            this._bg = null;
            this._checkBox = null;
            this._txtType = null;
            this._txtDate = null;
            this._txtStatus = null;
            this._txtStaticTitle = null;
            this._txtTitle = null;
            this._btnGetAttachment = null;
            this._bmpStatus = null;
            this._bmpAttachment = null;
            return;
        }// end function

        override public function set data(param1:Object) : void
        {
            super.data = param1;
            this._data = param1;
            if (this._bmpAttachment)
            {
                this._bmpAttachment.dispose();
                this._bmpAttachment = null;
            }
            if (this._bmpStatus)
            {
                this._bmpStatus.dispose();
                this._bmpStatus = null;
            }
            var _loc_2:* = this.data as SMail;
            this._txtDate.text = _loc_2.mailDt.fullYear + "/" + (_loc_2.mailDt.month + 1) + "/" + _loc_2.mailDt.date;
            if (_loc_2.type == EMailType._EMailTypePlayer)
            {
                this._txtType.text = "私人邮件";
                this._txtTitle.text = FilterText.instance.getFilterStr(_loc_2.title);
            }
            else if (_loc_2.type == EMailType._EMailTypeSystem)
            {
                this._txtType.text = "系统邮件";
                this._txtTitle.text = _loc_2.title;
            }
            else if (_loc_2.type == EMailType._EMailTypeGuild)
            {
                this._txtType.text = "公会邮件";
                this._txtTitle.text = FilterText.instance.getFilterStr(_loc_2.title);
            }
            if (_loc_2.status == 1)
            {
                this._txtStatus.text = "[未读]";
                this._txtStatus.textColor = GlobalStyle.colorHongUint;
                this._bmpStatus = UIFactory.bitmap(ImagesConst.mailUnRead, 212, 2, this);
            }
            else
            {
                this._txtStatus.text = "[已读]";
                this._txtStatus.textColor = GlobalStyle.colorHuangUint;
                this._bmpStatus = UIFactory.bitmap(ImagesConst.mailRead, 212, 2, this);
            }
            if (Cache.instance.mail.checkMailhadAttach(_loc_2))
            {
                this._btnGetAttachment.visible = true;
                if (_loc_2.status == 1)
                {
                    this._bmpAttachment = UIFactory.bitmap(ImagesConst.mailAttach1, 198, 3, this);
                }
                else
                {
                    this._bmpAttachment = UIFactory.bitmap(ImagesConst.mailAttach2, 198, 3, this);
                }
            }
            else
            {
                this._btnGetAttachment.visible = false;
            }
            return;
        }// end function

        public function get mailSelected() : Boolean
        {
            return this._checkBox.selected;
        }// end function

        public function set mailSelected(param1:Boolean) : void
        {
            this._checkBox.selected = param1;
            return;
        }// end function

        override public function get selected() : Boolean
        {
            return super.selected;
        }// end function

        override public function set selected(param1:Boolean) : void
        {
            super.selected = param1;
            return;
        }// end function

    }
}
